import * as React from 'react';
import { Icon } from '../components/Icon';
export function ChildrenAttribute({ children, buttonContent }) {
  const [isOpenState, setIsOpenState] = React.useState(true);
  const toggleButton = () => {
    setIsOpenState(isOpenState => !isOpenState);
  };
  return (
    <div>
      <button
        className={
          isOpenState ? 'childrenButton' : 'childrenButton childrenAttribute'
        }
        onClick={toggleButton}
      >
        <Icon
          icon="add"
          style={{
            color: isOpenState ?"var(--color-geekblue-9)":"var(--color-gray-7)",
            verticalAlign: 'middle',
            marginRight: '6px',
            height: '18px',
            transition: 'transform 0.2s ease',
            transform: isOpenState ? 'rotate(0deg)' : 'rotate(45deg)',
          }}
          onClick={undefined}
        ></Icon>
        {buttonContent}
      </button>
      <div className="childrenCollapse">{children}</div>
      <style jsx>{`
        .childrenButton {
          height: 28px;
          color: var(--color-geekblue-9);
          background-color: var(--color-geekblue-1);
          border: 1px solid var(--color-geekblue-3);
          display: inline-block;
          white-space: nowrap;
          text-align: center;
          box-sizing: border-box;
          outline: none;
          margin: 0;
          padding: 4px 12px;
          font-size: 12px;
          line-height: 20px;
          border-radius: 4px;
          font-weight: 600;
          margin-top: 12px;
        }
        .childrenButton:hover {
          cursor: pointer;
        }
        .childrenAttribute {
          width: 100%;
          text-align: left;
          background: var(--color-white);
          border: 1px solid var(--color-gray-5);
          border-color: var(--color-gray-5);
          color: var(--color-gray-10);
          border-bottom-left-radius: 0px;
          border-bottom-right-radius: 0px;
        }
        .childrenCollapse {
          display: ${isOpenState ? 'none' : ''};
          background: var(--color-white);
          border: 1px solid var(--color-gray-5);
          border-color: var(--color-gray-5);
          color: var(--color-gray-10);
          border-top-width: 0px;
          padding: 8px 16px;
          border-bottom-left-radius: 4px;
          border-bottom-right-radius: 4px;
        }
      `}</style>
    </div>
  );
}
